//
//  CYMineActionCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/11.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYMineActionCell.h"



@implementation CYMineActionCellObject

@end



@interface CYMineActionCell ()

@property(nonatomic, strong)UIImageView *iconImageView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UIImageView *arrowImageView;
@property(nonatomic, strong)UIImageView *bottomLine;

@property(nonatomic, strong)UILabel *hintLabel;
@property(nonatomic, strong)UIImageView *hintDot;

@end


@implementation CYMineActionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
        [self.contentView addSubview:self.iconImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = HEXCOLOR(@"444444");
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.titleLabel];
        
        self.arrowImageView = [[UIImageView alloc] initWithImage:CYImage(@"public_cell_arrow")];
        [self.contentView addSubview:self.arrowImageView];
        
        self.hintLabel = [[UILabel alloc] init];
        self.hintLabel.textColor = HEXCOLOR(@"B4B4B4");
        self.hintLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.hintLabel];
        
        self.hintDot = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:HEXCOLOR(@"E94559") size:CGSizeMake(6, 6)]];
        self.hintDot.layer.masksToBounds = YES;
        self.hintDot.layer.cornerRadius = self.hintDot.width / 2;
        [self.contentView addSubview:self.hintDot];
        
        self.bottomLine = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:HEXCOLOR(@"ECECEC") size:CGSizeMake(1, 1)]];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 50;
}

- (BOOL)shouldUpdateCellWithObject:(CYMineActionCellObject *)object
{
    self.iconImageView.image = CYImage(object.icon);
    
    self.titleLabel.text = object.title;
    
    self.bottomLine.hidden = object.isBottom;
    
    self.hintLabel.hidden = object.hintText.length == 0;
    self.hintDot.hidden = !object.hintDot;
    self.hintLabel.text = object.hintText;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.iconImageView.centerY = self.contentView.height / 2;
    self.iconImageView.left = 20;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.centerY = self.contentView.height / 2;
    self.titleLabel.left = 52;
    
    self.arrowImageView.centerY = self.contentView.height / 2;
    self.arrowImageView.right = self.contentView.width - 12;
    
    [self.hintLabel sizeToFit];
    self.hintLabel.centerY = self.contentView.height / 2;
    self.hintDot.centerY = self.contentView.height / 2;
    self.hintDot.right = self.contentView.width - 32;
    self.hintLabel.right = self.contentView.width - (self.hintDot.hidden ? 32 : 43);
    
    self.bottomLine.width = self.contentView.width - 48;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.bottom = self.contentView.height;
    self.bottomLine.right = self.contentView.width;
}

@end
